<?php
	/*\
     *  Gladius - oh.framework
     *  ----------------------
     *  name: gladius
     *  sign: 
     *  description: manage a flatfile database
    \*/	oh_module_header();
	

	require_once(dirname(__FILE__)."/gladius-0.8.1/gladius.php");
	require_once(dirname(__FILE__)."/gladius.class.php");


    function oh_module_gladius($tokens) {
		return oh_this();
	} 
	
	
	class oh_class_gladius extends the_gladius {

		public $db;

		public $ready;

		function oh_class_gladius() {
			global $oh;
			
			$this->db = new Gladius();
			
			if (oh("config")->have("db.path")) {
				$path = oh("config.db.path");	
			} else {
				$path = dirname(__FILE__).'/db/';
				oh("config")->set("db.path",$path);
			}
			if (oh_get_file_permission($path) == "0777") {
				$this->db->SetDBRoot($path);
			
				if (oh("config")->have("db.name")) {
					$name = oh("config.db.name");
				} else {
					$name = "DB0";
				}
				if (!$this->db_exists($name)) {
					$this->db_create($name);
				} 
				$this->db_use($name);
				$this->ready = true;
			} else {
				oh_message(OH_EM004.$path.br."Use: sudo chmod 777 ".$path);
				$this->ready = false;			
			}
		}
		function is_ready() {
			return true;
		}
	}
	
	
	global $oh_object_gladius;
	$oh_object_gladius = new oh_class_gladius();
?>
